package com.lyz.util;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;


public class FileUtil {
	
	
	private static final Logger logger = Logger.getLogger(FileUtil.class);
	
	private List<String> fileList = null;
	
	
	/**
	 * 
	 * @param dir
	 * @param filter file name begin with filter
	 * @return filename
	 */
	public List<String> getFileList(String dir, String start, String end, boolean subTree){
		
//		logger.info("getFileList:dir="+dir+";filter="+filter+"subTree="+subTree);
		
		File file = new File(dir);
		if(fileList == null){
			fileList = new LinkedList<String>();
		}
		File[] files = null;
		
		if(!file.isDirectory()){
			return null;
		}
		
		files = file.listFiles();
		for(File f : files){
			if(f.isDirectory() && subTree){
				getFileList(f.getAbsolutePath(),start,end,subTree);
			}else{
				if(f.getName().startsWith(start) && f.getName().endsWith(end)){					
					fileList.add(f.getName());
//					logger.info(f.getName()+" in fileList");
				}
				
			}
		}
		
		return fileList;
	}
	

	
	

	/**
	 * @param args
	 */
//	public static void main(String[] args) {
//		
//		List<String>  list = new FileUtil().getFileList("/home/iqiyi/testFiles/", "", false);
//		for(String s : list){
//			System.out.println(s);
//		}
//
//	}

}
